<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function fun(){
				if(event.keyCode<48||event.keyCode>57){
					console.error("只允许输入数字")
					//event.preventDefault()
					return false;
				}
			}
			
		</script>
	</head>
	<body>
		请输入数字：<input type="text" onkeypress="return fun()"/>
		
	</body>
</html>
